package com.adinnet.admin.sentence.service.impl;

import com.adinnet.admin.sentence.model.Sentence;
import com.adinnet.admin.sentence.mapper.SentenceMapper;
import com.adinnet.admin.sentence.service.SentenceService;
import com.adinnet.admin.video.model.Video;
import com.adinnet.core.JsonResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 跟随训练表（短句） 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Service
public class SentenceServiceImpl extends ServiceImpl<SentenceMapper, Sentence> implements SentenceService {


    @Autowired
    private SentenceMapper sentenceMapper;

    /**
     * @param keyword:
     * @Description: 短句列表
     * @author zYshuai
     * @Date: 2020/12/15 10:06
     * @return: java.util.List<com.adinnet.admin.sentence.model.Sentence>
     */
    @Override
    public List<Sentence> sentenceList(String keyword) {
        return sentenceMapper.selectList(new QueryWrapper<Sentence>().eq("deleted", 0).eq(StringUtils.isNotBlank(keyword), "sentence_name", keyword).orderByDesc("created_date"));
    }

    /**
     * @param sentenceId:
     * @Description: 删除短句
     * @author zYshuai
     * @Date: 2020/12/15 10:06
     * @return: com.adinnet.core.JsonResult
     */
    @Override
    public JsonResult delete(Integer sentenceId) {
        Sentence sentence = new Sentence();
        sentence.setDeleted(true);
        sentenceMapper.update(sentence, new QueryWrapper<Sentence>().eq("id", sentenceId));
        return JsonResult.ok("删除成功");
    }
}
